package com.gdwhomework.chapter07;

public class HomeWork001 {
    public static void main(String[] args) {
        Person arr[] = new Person[3];
        Person person1 = new Person("tom", 12, "学生");
        arr[0] = person1;
        arr[1] = new Person("jack",70,"教授");
        arr[2] = new Person("frank",40,"工人");
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
        person1.bubbles_(arr);
        System.out.println("----------排序后------------");
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
}

/*
定义一个Person类{name，age，job}，初始化Person对象数组，有
三个peron对象 按照age从小到大排序，使用冒泡排序
 */
class Person {
    private String name;
    private int age;
    private String job;

    public Person(String name, int age, String job) {
        this.name = name;
        this.age = age;
        this.job = job;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public void bubbles_(Person arr[]) {
        for (int i = 0; i < arr.length - 1; i++) {

            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j].age > arr[j + 1].age) {
                    Person person = new Person("tmp", 18, "tmp");
                    person = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = person;
                }
            }
        }
    }

//    public void showinfo(){
//        System.out.println("name= "+getName()+" age ="+getAge()+" job :"+getJob());
//    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", job='" + job + '\'' +
                '}';
    }
}
